package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @ClassName 按字典序排在最后的子串
 * @Description TODO
 * @Date 2019/8/18 11:50
 * @Version 1.0
 **/
public class 按字典序排在最后的子串 {


    String str = "abcdefghijklmnopqrstuvwxyz";

    public String lastSubstring(String s) {
        int[] arrs = new int[1000];
        String result = "", temp = "";
        int pre = 0, target = 0;
        Character ch = null;
        for (int i = str.length()-1; i >= 0; i--) {
            ch = str.charAt(i);
            if (s.contains(ch+"")) {
//                if (ch == 'a') return result;
                target = s.indexOf(ch);
                pre = target;
                result = s.substring(target);
                System.out.println(result);
                while ((target = s.indexOf(ch,target+1)) >= 0) {
                    if (pre + 1 == target) {
                        pre = target;
                        continue;
                    }
                    temp = s.substring(target);
                    if (temp.compareTo(result) > 0) {
                        result = temp;
                    }
                }
                break;
            }
        }
        return result;
    }
}
